package com.nuc.bigdata.controller;

import com.nuc.bigdata.orm.dto.NewsCommentsDto;
import com.nuc.bigdata.orm.feign.CommodityCommentsFeign;
import com.nuc.bigdata.service.CommodityCommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 商品评论Controller
 * @author JackLuo
 * @date 2019/12/3
 */
@RestController
@RequestMapping("/oa-comments")
public class CommodityCommentsController {
    private final CommodityCommentsService commentsService;

    @Autowired
    CommodityCommentsController (CommodityCommentsService commentsService) {
        this.commentsService = commentsService;
    }

    /**
     * 创建新评论
     * @param commodityId 商品唯一标识
     * @param commentsDto 评论dto
     */
    @PostMapping("/commodity/{commodityId}")
    public void createCommodityComments(@PathVariable("commodityId")String commodityId,
                                     @RequestBody NewsCommentsDto commentsDto) {
        commentsService.createComments(commodityId, commentsDto);
    }

    /**
     * 获取商品评论信息
     * @param commodityId 商品唯一标识
     * @param pageSize 页码
     * @return 包含商品评论feign的ArrayList
     */
    @GetMapping("/commodity/{commodityId}")
    public ArrayList<CommodityCommentsFeign> queryCommodityCommentsFeign(@PathVariable("commodityId")String commodityId,
                                                                      @RequestParam("pageSize") Long pageSize){
        return (ArrayList<CommodityCommentsFeign>) commentsService.listById(commodityId, pageSize);
    }

    /**
     * 点赞用户评论
     * @param commodityCommentId 评论唯一标识
     * @param userId 用户唯一标识
     */
    @PostMapping("/commodity/{commodityCommentId}/like")
    public void toCommodityCommentLike(@PathVariable("commodityCommentId")String commodityCommentId,
                                   @RequestParam("userId") String userId){
        commentsService.toCommentLike(commodityCommentId, userId);
    }
}
